<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

class Classroom extends Model
{
    protected $table = 'classroom';

    public function scopeWhereId(Builder $builder,$id){
        return $builder->where('id',$id);
    }

    //查询店铺名
    public function store()
    {
        return $this->hasOne('App\Models\Store','id','store_id');
    }

    /**
     * 获取器
     */
    public function getImageAttribute($value)
    {
        return getDomain() . '/' . $value;
    }

    /**
     * 轮播图设置器
     */
    public function setClassImgAttribute($value)
    {
        if (is_array($value) && !empty($value)) {
            $this->attributes['class_img'] = implode(";", $value);
        }
    }

    /**
     * 轮播图
     */
    public function getClassImgAttribute($value)
    {
        $result = [];
        $result = explode(';', $value);

        foreach ($result as &$v){
            $v = getDomain() . '/' . $v;
        }

        return $result;
    }

}
